/*
 * Created on 2005-10-14
 *
 */
package com.yl.cap.analyst.work.dao;

import java.util.Date;
import java.util.List;

import net.sf.hibernate.Hibernate;
import net.sf.hibernate.Query;
import net.sf.hibernate.type.Type;

import org.faquir.hibernate.queryhelper.DAOHelper;
import org.faquir.hibernate.queryhelper.Page;
import jaoso.framework.dao.hibernate.BaseDAOImpl;

public class JobTaskDAOImpl extends BaseDAOImpl implements JobTaskDAO
{

    public List getAllJobName()
    {
        String hql = "select distinct jl.tigerName from JobLog as jl";
        return this.getHibernateTemplate().find(hql);
    }

    public Page getLastLog(int currentPage, int pageSize) throws Exception
    {
        String hql = "from JobLog jl order by jl.beginTime desc";
        DAOHelper helper = new DAOHelper();
        return helper.queryPage(this.getSession(),hql,currentPage,pageSize);
    }

    public Page getJobByNameDate(String name, Date from, Date to, int currentPage, int pageSize) throws Exception
    {
        String hql = "from JobLog as jl where jl.tigerName=? and jl.beginTime between ? and ? order by jl.beginTime desc";
        Object[] value = {name,from,to};
        Type[] type = {Hibernate.STRING,Hibernate.DATE,Hibernate.DATE};
        DAOHelper helper = new DAOHelper();
        Query q = this.getSession().createQuery(hql);
        return helper.queryPage(this.getSession(),q,currentPage,pageSize,type,value);
    }
}
